package com.activemanager.workoutAssistant;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.example.android.navigationdrawerexample.R;
import com.example.android.navigationdrawerexample.R.id;
import com.example.android.navigationdrawerexample.R.layout;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class WorkoutHistory_C1 extends Activity {
	
	
	private List<StoreData> mData1;
	private List<StoreData> mData2;
	private List<StoreData> mData3;
	private List<StoreData> mData4;
	ListView list1 = null;
	ListView list2 = null;
	ListView list3 = null;
	ListView list4 = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.workout_history_c1);
//		View rootView = inflater.inflate(R.layout.workout_history_c1, container, false);
		mData1 = new ArrayList<StoreData>();
		mData2 = new ArrayList<StoreData>();
		mData3 = new ArrayList<StoreData>();
		
		initPic();
		
		list1 = (ListView) findViewById(R.id.LVUpcome);
		list2 = (ListView) findViewById(R.id.LVTodayWeek);
		list3 = (ListView) findViewById(R.id.LVLastWeek);
		list4 = (ListView) findViewById(R.id.LVProvious);
		
		String[] mFrom = new String[] { "item_img", "time_text","content_text","more_img" };
		int[] mTo = new int[] { R.id.listitem_image, R.id.listitem_time, R.id.listitem_name, R.id.img_more };
		
		String[] item_img = { "choose_u160_normal" };
		String[] time_text = { "Oct 03, 20:00-21:00" };
		String[] content_text = { "Digital Traning" };
		String[] more_img = { "" };
		
		List<Map<String, Object>> mList = new ArrayList<Map<String, Object>>();
		Map<String, Object> mMap = null;
		for (int i = 0; i < item_img.length; i++) {
			mMap = new HashMap<String, Object>();
			int drawable = getResources().getIdentifier(
					item_img[i], "drawable",
					getPackageName());
			mMap.put("item_img", drawable);
			mMap.put("time_text", time_text[i]);
			mMap.put("content_text", content_text[i]);
			mMap.put("more_img", "");
			mList.add(mMap);
		}
		SimpleAdapter mAdapter = new SimpleAdapter(WorkoutHistory_C1.this,
				mList, R.layout.workout_history_item, mFrom, mTo);
		list1.setAdapter(mAdapter);
		list1.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
			
			}});
		
		
		String[] item_img1 = { "choose_u155_normal","choose_u156_normal" };
		String[] time_text1 = { "Sep 28, 20:00","Sep 28, 14:00" };
		String[] content_text1 = { "Jogging, 4.5 km, 556kcal", "Badminton, 60mins,348strokes" };
		String[] more_img1 = { "menu_button_u45_normal", "menu_button_u45_normal" };
		List<Map<String, Object>> mList1 = new ArrayList<Map<String, Object>>();
		Map<String, Object> mMap1 = null;
		for (int i = 0; i < item_img1.length; i++) {
			mMap1 = new HashMap<String, Object>();
			int drawable = getResources().getIdentifier(
					item_img1[i], "drawable",
					getPackageName());
			int more = getResources().getIdentifier(
					more_img1[i], "drawable",
					getPackageName());
			mMap1.put("item_img", drawable);
			mMap1.put("time_text", time_text1[i]);
			mMap1.put("content_text", content_text1[i]);
			mMap1.put("more_img", more);
			mList1.add(mMap1);
		}
		SimpleAdapter mAdapter1 = new SimpleAdapter(WorkoutHistory_C1.this,
				mList1, R.layout.workout_history_item, mFrom, mTo);
		list2.setAdapter(mAdapter1);
		list2.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
			
			}});
		
		
		String[] item_img2 = { "choose_u155_normal" };
		String[] time_text2 = { "Sep 21" };
		String[] content_text2 = { "Jogging, 4.2 km, 520kcal"};
		String[] more_img2 = { "" };
		List<Map<String, Object>> mList2 = new ArrayList<Map<String, Object>>();
		Map<String, Object> mMap2 = null;
		for (int i = 0; i < item_img2.length; i++) {
			mMap2 = new HashMap<String, Object>();
			int drawable = getResources().getIdentifier(
					item_img2[i], "drawable",
					getPackageName());
			mMap2.put("item_img", drawable);
			mMap2.put("time_text", time_text2[i]);
			mMap2.put("content_text", content_text2[i]);
			mMap2.put("more_img", "");
			mList2.add(mMap2);
		}
		SimpleAdapter mAdapter2 = new SimpleAdapter(WorkoutHistory_C1.this,
				mList2, R.layout.workout_history_item, mFrom, mTo);
		list3.setAdapter(mAdapter2);
		list3.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
			
			}});
		
		
		String[] item_img3 = { "choose_u155_normal", "choose_u156_normal","choose_u156_normal","choose_u156_normal"};
		String[] time_text3 = { "Sep 13","Sep 12","Sep 11","Sep 10" };
		String[] content_text3 = { "Jogging 4.0km,516ka","Badminton 60mins,348strokes",
				"Badminton 60mins,348strokes","Badminton 60mins,31strokes"};
		String[] more_img3 = { "","menu_button_u45_normal","menu_button_u45_normal","" };
		List<Map<String, Object>> mList3 = new ArrayList<Map<String, Object>>();
		Map<String, Object> mMap3 = null;
		for (int i = 0; i < item_img3.length; i++) {
			mMap3 = new HashMap<String, Object>();
			int drawable = getResources().getIdentifier(
					item_img3[i], "drawable",
					getPackageName());
			int more = getResources().getIdentifier(
					more_img3[i], "drawable",
					getPackageName());
			mMap3.put("item_img", drawable);
			mMap3.put("time_text", time_text3[i]);
			mMap3.put("content_text", content_text3[i]);
			mMap3.put("more_img", more);
			mList3.add(mMap3);
		}
		SimpleAdapter mAdapter3 = new SimpleAdapter(WorkoutHistory_C1.this,
				mList3, R.layout.workout_history_item, mFrom, mTo);
		list4.setAdapter(mAdapter3);
		list4.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
			
			}});

//		getData();
//		MyAdapter adapter1 = new MyAdapter(mData1, WorkoutHistory_C1.this);
//		list1.setAdapter(adapter1);
//		MyAdapter adapter2 = new MyAdapter(mData2, WorkoutHistory_C1.this);
//		list2.setAdapter(adapter2);
//		MyAdapter adapter3 = new MyAdapter(mData3, WorkoutHistory_C1.this);
//		list3.setAdapter(adapter3);

	}
	
	private void initPic() {
		// TODO Auto-generated method stub
		BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
		
		ScrollView bgLayout = (ScrollView) findViewById(R.id.scrollView1);
//		InputStream is = getResources().openRawResource(
//				R.drawable.background_normal);
//		Bitmap bgbit = BitmapFactory.decodeStream(is, null, opt);
//		bgLayout.setBackgroundDrawable(new BitmapDrawable(bgbit));
		bgLayout.setBackgroundResource(R.drawable.bg_540);
		
		
	}

	
	public final class ViewHolder {
		public ImageView image;
		public TextView Message;
		public TextView time;
	}

	public class MyAdapter extends BaseAdapter {
		List<StoreData> list = new ArrayList<StoreData>();
		private LayoutInflater mInflater;
		Context context;

		public MyAdapter(List<StoreData> list, Context context) {
			this.list = list;
			this.context = context;
			this.mInflater = LayoutInflater.from(context);
		}

		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return list.get(arg0);
		}

		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			ViewHolder holder = null;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = mInflater.inflate(R.layout.workout_history_item, null);
				holder.image = (ImageView) convertView
						.findViewById(R.id.listitem_image);
				holder.time = (TextView) convertView
						.findViewById(R.id.listitem_time);
				holder.Message = (TextView) convertView
						.findViewById(R.id.listitem_name);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			final StoreData mess = (StoreData) list.get(position);
			// ����ͼ��
			holder.time.setText(mess.getTime());
			holder.Message.setText(mess.getMessage());
			return convertView;
		}
	}
	public class StoreData {
		private String time;
		private String Message;
		public String getTime() {
			return time;
		}
		public void setTime(String time) {
			this.time = time;
		}
		public String getMessage() {
			return Message;
		}
		public void setMessage(String message) {
			Message = message;
		}

	}

}
